(defrule conte-infantil
	(conte)    
   
	=>
    
    ; DESCARTAR
    (do-for-all-instances ((?llibre Llibre)) TRUE
 
        	(bind ?aux 0)
	        (loop-for-count (?j 1 (length$ ?llibre:genere)) do
	            (bind ?gen_dir (nth$ ?j ?llibre:genere)) 
	           	(bind ?gen (send (instance-address * ?gen_dir) get-nom_genere))  	
	 
            	(if (eq ( str-compare ?gen "Conte" )0)  then
                	(bind ?aux 1)
                )
	        ) 
        	(if (eq ?aux 0) then
           		(send ?llibre delete)
            ;(printout t ?llibre:titol crlf)
            )
    )
    
    ;PREGUNTES
	(bind ?res (si-no "Vols un conte classic o actual? [classic | actual] "))   
    
    ; ASSERTS
    (assert (conte ?res))
)


(defrule es-jove
    (not (edat))
	?lector <- (dades-lector (edat Juvenil))
	=>
    ; DESCARTAR
    (do-for-all-instances ((?llibre Llibre)) TRUE
        
        	(bind ?aux 0)
	        (loop-for-count (?j 1 (length$ ?llibre:genere)) do
	            (bind ?gen_dir (nth$ ?j ?llibre:genere)) 
	           	(bind ?gen (send (instance-address * ?gen_dir) get-nom_genere))  	
	 
            	(if (eq ( str-compare ?gen "Juvenil" )0)  then
                	(bind ?aux 1)
                )
	        ) 
        	(if (eq ?aux 0) then
           		(send ?llibre delete)
            (printout t ?llibre:titol crlf)
            )
    )
    
    ;PREGUNTES
	(bind ?res (si-no "T'agraden els skates? [si | no] "))   
    
    ; ASSERTS
    (assert (edat))
)

(defrule es-adult
    (not (edat))
	?lector <- (dades-lector (edat Adult))
	=>
    ; DESCARTAR
    (do-for-all-instances ((?llibre Llibre)) TRUE
        
        	(bind ?aux 0)
	        (loop-for-count (?j 1 (length$ ?llibre:genere)) do
	            (bind ?gen_dir (nth$ ?j ?llibre:genere)) 
	           	(bind ?gen (send (instance-address * ?gen_dir) get-nom_genere))  	
	 
            	(if (eq ( str-compare ?gen "Adult" )0)  then
                	(bind ?aux 1)
                )
	        ) 
        	(if (eq ?aux 0) then
           		(send ?llibre delete)
            (printout t ?llibre:titol crlf)
            )
    )
    
    ;PREGUNTES
	(bind ?res (si-no "T'agraden les coses aburrides? [si | no] "))   
    
    ; ASSERTS
    (assert (edat))
)

(defrule es-home
    (not (sexe))
	?lector <- (dades-lector (sexe h))
	=>
    ; DESCARTAR
    
    ;PREGUNTES
	(bind ?res (si-no "T'agraden els maxots? [si | no] "))   
    
    ; ASSERTS
    (assert (sexe))
)

(defrule es-dona
    (not (sexe))
	?lector <- (dades-lector (sexe d))
	=>
    ; DESCARTAR
    
    ;PREGUNTES
	(bind ?res (si-no "T'agraden les floretes? [si | no] "))   
    
    ; ASSERTS
    (assert (sexe))
)

(defrule llibre-de-butxaca
    (not (lloc))
	?lector <- (dades-lector (llocLectura fora))
	=>
    ; DESCARTAR
    (do-for-all-instances ((?llibre Llibre)) TRUE
        
        	(bind ?aux 0)
	        (loop-for-count (?j 1 (length$ ?llibre:genere)) do
	            (bind ?gen_dir (nth$ ?j ?llibre:genere)) 
	           	(bind ?gen (send (instance-address * ?gen_dir) get-nom_genere))  	
	 
            	(if (eq ( str-compare ?gen "Adult" )0)  then
                	(bind ?aux 1)
                )
	        ) 
        	(if (eq ?aux 0) then
           		(send ?llibre delete)
            (printout t ?llibre:titol crlf)
            )
    )
    
    ;PREGUNTES
	(bind ?res (si-no "T'agraden els llibres petits eh??? [si | no] "))   
    
    ; ASSERTS
    (assert (lloc))
)

(defrule llibre-per-casa
    (not (lloc))
	?lector <- (dades-lector (llocLectura casa))
	=>
    ; DESCARTAR
    
    ;PREGUNTES
	(bind ?res (si-no "T'agraden les floretes? [si | no] "))   
    
    ; ASSERTS
    (assert (lloc))
)

(defrule llegir-diariament
    (not (freq))
	?lector <- (dades-lector (frequencia diariament))
	=>
    ; DESCARTAR
    
    ;PREGUNTES
	(bind ?res (si-no "Llegeixes cada dia eh? [si | no] "))   
    
    ; ASSERTS
    (assert (freq))
)

(defrule llegir-ocasionalment
    (not (freq))
	?lector <- (dades-lector (frequencia ocasionalment))
	=>
    ; DESCARTAR
    
    ;PREGUNTES
	(bind ?res (si-no "Llegeixes poc eh? [si | no] "))   
    
    ; ASSERTS
    (assert (freq))
)